package com.solutionsfit.timesheet

enum PayPeriodType {
	FIRST(1), SECOND(16)

	int startDate
	
	PayPeriodType(int startDate) {
		this.startDate = startDate
	}
	
	private Calendar getCalendarDate(int month, int year, int startDate)
	{
		Calendar calendar = Calendar.getInstance()
		
		calendar.clear()
		calendar.set(year, month, startDate)
		
		return calendar
	}
	
	Date getStartDate(int month, int year) 
	{
		getCalendarDate(month, year, this.startDate).time
	}
	
	Date getEndDate(int month, int year)
	{
		Date endDate
		
		if(this == FIRST)
		{
			endDate = getCalendarDate(month, year, 15).time
		}
		else
		{
			Calendar startCalendarDate = 
				getCalendarDate(month, year, this.startDate)
		
			Calendar endCalendarDate = getCalendarDate(month, year,
				startCalendarDate.getActualMaximum(Calendar.DATE))
			
			endDate = endCalendarDate.time
		}
		
		return endDate
	}
}
